/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.midlet.*;

/**
 * @author USER
 */
public class MMIDlet extends MIDlet implements CommandListener {

    public static int SOUND = 1;
    public static int LANDSCAPE = 1;
    protected Display display;      //reference to display
    private Command cmdExit;
    //canvas
    private MenuCanvas menuCanvas;
    private SplashScreen splashScreen;
    private AskSoundScreen askSoundScreen;
    private TitleScreen titleScreen;
    //private MainGame mainGame;
    //private GameBoard gameBoard;
    private Board board;
    
    public static int WIDTH, HEIGHT;
    public static Font SMALL_PLAIN_FONT;
    public static Font SMALL_BOLD_FONT;
    public static Font LARGE_BOLD_FONT;

    public MMIDlet() {
        display = Display.getDisplay(this);

        SMALL_PLAIN_FONT = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL);
        SMALL_BOLD_FONT = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL);
        LARGE_BOLD_FONT = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_LARGE);
    }

    public void startApp() {
        splashScreen = new SplashScreen(this);
        display.setCurrent(splashScreen);
        splashScreen.start();

        /*
        String[] nama = new String[23];
        for(int i=0; i<23; i++){
            nama[i] = " nama " + i;
        }
        for(int i=0; i<3; i++){
            for(int j=0; j<23; j++){
                System.out.println(i + nama[j]);
            }
        }
        
        Question q = new Question();
        //q.setMatter("26","-", "24");
        q.setMatter(6, "+", 3);
        System.out.println("test : " + q.answer);
        q.setMatter(6, "-", 3);
        System.out.println("test : " + q.answer);
        q.setMatter(6, "x", 3);
        System.out.println("test : " + q.answer);
        q.setMatter(6, "/", 3);
        System.out.println("test : " + q.answer);
        //showMenuCanvas();
         * 
         */
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
        //menuCanvas.stop();
    }

    public void commandAction(Command c, Displayable d) {
        if (c == cmdExit) {
            destroyApp(true);
            notifyDestroyed();
        }
    }

    public void exit() {
        /*
        menuCanvas = null;
        screenOne = null;
        screenTwo = null;
        screenThree = null;
        screenFour = null;
        askSoundScreen = null;
         * 
         */

        destroyApp(true);
        notifyDestroyed();
    }    

    public void showAskSoundScreen() {
        //CLICKED = 0;
        //menuCanvas.stop();
        splashScreen = null;
        askSoundScreen = new AskSoundScreen(this);
        display.setCurrent(askSoundScreen);
        //askSoundScreen.start();
    }

    public void showTitleScreen() {
        //CLICKED = 0;
        //menuCanvas.stop();
        askSoundScreen = null;
        titleScreen = new TitleScreen(this);
        display.setCurrent(titleScreen);
        titleScreen.start();
    }

    public void showMenuCanvas() {
        //CLICKED = 0;
        //menuCanvas.stop();
        titleScreen = null;
        menuCanvas = new MenuCanvas(this);
        display.setCurrent(menuCanvas);
        menuCanvas.start();
    }

    public void showMainGame() {
        //CLICKED = 0;
        menuCanvas.stop();
        menuCanvas = null;
        /*
        gameBoard = new GameBoard(this);
        display.setCurrent(gameBoard);
        gameBoard.start();
         * 
         */
        board = new Board(this);
        display.setCurrent(board);
        board.start();
    }

    /*
    public void beforeShow(int no) {
    if (no == 0) {
    menuCanvas.stop();
    menuCanvas = null;
    showScreen(1);
    } else if (no == 1) {
    screenOne.stop();
    screenOne = null;
    showScreen(2);
    } else if (no == 2) {
    screenTwo.stop();
    screenTwo = null;
    showScreen(3);
    } else if (no == 3) {
    screenThree.stop();
    screenThree = null;
    showScreen(4);
    } else if (no == 4) {
    screenFour.stop();
    screenFour = null;
    showScreen(0);
    }
    }
     *
     */

    /*
    private void showScreen(int no) {
    if (no == 0) { // goto screenOne
    currentPage = 0;
    menuCanvas = new MainGame(this);
    display.setCurrent(menuCanvas);
    menuCanvas.start();
    CLICKED = 0;
    } else if (no == 1) { // goto screenOne
    currentPage = 1;
    screenOne = new ScreenOne(this);
    display.setCurrent(screenOne);
    screenOne.start();
    CLICKED = 0;
    } else if (no == 2) { // goto screenTwo
    currentPage = 2;
    screenTwo = new ScreenTwo(this);
    screenTwo.setCommandListener(this);
    display.setCurrent(screenTwo);
    screenTwo.start();
    CLICKED = 0;
    } else if (no == 3) { // goto screenThree
    currentPage = 3;
    screenThree = new ScreenThree(this);
    screenThree.setCommandListener(this);
    display.setCurrent(screenThree);
    screenThree.start();
    CLICKED = 0;
    } else if (no == 4) { // goto screenFour
    currentPage = 4;
    screenFour = new ScreenFour(this);
    screenFour.setCommandListener(this);
    display.setCurrent(screenFour);
    screenFour.start();
    CLICKED = 0;
    }
    }
     * 
     */
}

